local m = require('utils.vim')
local w = require('utils.win')

-- window management
m.map("n", ";q", "<C-w>c",{desc="close current window"})
m.map("n", ";w", "<C-w>w",{desc="switch between windows"})

m.map("n", ";v", "<C-w>v",{desc="split window vertically"})
m.map("n", ";h", "<cmd>split<CR>",{desc="split window horizontally"})
m.map("n", ";o", "<cmd>only<CR>",{desc="close other windows"})
-- Note: may confilict with tide plugin hints.dictionary (q,w,v,h,o must excluded)

m.map('n',"z<enter>",function()
    w.float2normal()
end,{desc="close window and replace current buffer"})

m.map("n","q",w.close_current_floating_window,{desc="close float window"})

local fk = vim.api.nvim_feedkeys
m.map({ 't','n' },
    '<M-d>',
    function()
        -- First exit terminal mode
        if vim.api.nvim_get_mode().mode == 't' then
            -- Exit terminal mode first
            fk(
                vim.api.nvim_replace_termcodes('<C-\\><C-N>', true, false, true),
                'n',
                true
            )
        end
        w.close_current()
    end
    ,{desc="close current window including Terminal"}
)

-- EOP
